package com.zjw.touchscreen.listener.lixiang;

import android.annotation.SuppressLint;
import android.graphics.Point;
import android.view.MotionEvent;
import android.view.View;

import java.util.LinkedList;

public class CenterTouchBoardListener implements View.OnTouchListener {

    private LinkedList<Point> points = new LinkedList<>();

    @SuppressLint("LongLogTag")
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        float x = event.getX();
        float y = event.getY();
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                points.clear();
                break;
            case MotionEvent.ACTION_MOVE:
                Point point = new Point((int) x, (int) y);
                points.add(point);
                break;
        }
        //发送鼠标移动事件
        if (points.size() < 2) {
            return true;
        }
        Point point0 = points.get(0);
        Point point1 = points.get(1);
        float sendX = point1.x - point0.x;
        float sendY = point1.y - point0.y;
        sendX = sendX > 127 ? 127 : sendX;
        sendY = sendY > 127 ? 127 : sendY;
        points.removeFirst();
        return true;
    }
}
